home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / x11 / rpg / crossfir.92 / crossfir / crossfire-0.92.5 / server / c_new.c < prev    next >
C/C++ Source or Header  |  1996-07-24  |  3KB  |  128 lines

  1. /*
  2.  * This file contains various commands that are used by the new client/server
  3.  *    ++Jam
  4.  */
  5.  
  6. #include <global.h>
  7. #include <commands.h>
  8. #include <sproto.h>
  9.  
  10. #ifndef tolower
  11. #define tolower(C)      (((C) >= 'A' && (C) <= 'Z')? (C) - 'A' + 'a': (C))
  12. #endif
  13.  
  14.  
  15. static int compare_A(const void *a, const void *b)
  16. {
  17.   return strcmp(((CommArray_s *)a)->name, ((CommArray_s *)b)->name);
  18. }
  19.  
  20. static CommArray_s *find_command_element(char *cmd, CommArray_s *commarray,
  21.     int commsize)
  22. {
  23.   CommArray_s *asp, dummy;
  24.   char *cp;
  25.  
  26.   for (cp=cmd; *cp; cp++)
  27.     *cp =tolower(*cp);
  28.  
  29.   dummy.name =cmd;
  30.   asp =(CommArray_s *)bsearch((void *)&dummy,
  31.                   (void *)commarray, commsize,
  32.                   sizeof(CommArray_s), compare_A);
  33.   return asp;
  34. }
  35.  
  36. int execute_newserver_command(object *pl, char *command)
  37. {
  38.  
  39.   CommArray_s *csp;
  40.   char *cp;
  41.  
  42.   pl->contr->has_hit=0;
  43.   /*
  44.    * No arguments?
  45.    */
  46.   if (!(cp=strchr(command, ' '))) {
  47.       if ((csp=find_command_element(command, NewServerCommands,
  48.     NewServerCommandSize))==NULL)
  49.         csp=find_command_element(command, Commands, CommandsSize);
  50.  
  51.     if (csp==NULL) {
  52.         char buf[MAX_BUF];
  53.  
  54.         sprintf(buf, "'%s' is not a valid command.", command);
  55.         new_draw_info(NDI_UNIQUE, 0,pl, buf);
  56.         return 0;
  57.     }
  58.     pl->speed_left -= csp->time;
  59. #if 0
  60.     if (csp->time && csp->time>pl->speed_left) {
  61. #endif
  62.     /* A character time can never exceed his speed (which in many cases,
  63.      * if wearing armor, is less than one.)  Thus, in most cases, if
  64.      * the command takes 1.0, the player's speed will be less than zero.
  65.      * it is only really an issue if time goes below -1
  66.      * Due to various reasons that are too long to go into here, we will
  67.      * actually still execute player even if his time is less than 0,
  68.      * but greater than -1.  This is to improve the performance of the
  69.      * new client/server.  In theory, it shouldn't make much difference.
  70.      */
  71.     if (csp->time && pl->speed_left<-2.0) {
  72.         LOG(llevDebug,"execute_newclient_command: Player issued command that takes more time than he has left.\n");
  73.     }
  74.     return csp->func(pl, NULL);
  75.   }
  76.   /*
  77.    * Command with some arguments
  78.    */
  79.  
  80.   *(cp++) ='\0';
  81.     if ((csp=find_command_element(command, NewServerCommands,
  82.     NewServerCommandSize))==NULL)
  83.         csp=find_command_element(command, Commands, CommandsSize);
  84.  
  85.     if (csp==NULL) {
  86.     char buf[MAX_BUF];
  87.  
  88.     sprintf(buf, "'%s' is not a valid command.", command);
  89.     new_draw_info(NDI_UNIQUE, 0,pl, buf);
  90.     return 0;
  91.     }
  92.     pl->speed_left -= csp->time;
  93.     if (csp->time && pl->speed_left<-1.0) {
  94.     LOG(llevDebug,"execute_newclient_command: Player issued command that takes more time than he has left.\n");
  95.     }
  96.     return csp->func(pl, cp);
  97. }
  98.  
  99. int command_run(object *op, char *params)
  100. {
  101.     op->contr->run_on=1;
  102.     return (move_player(op, params?atoi(params):0));
  103. }
  104.  
  105. int command_run_stop(object *op, char *params)
  106. {
  107.     op->contr->run_on=0;
  108.     return 1;
  109. }
  110.  
  111. int command_fire(object *op, char *params)
  112. {
  113.     op->contr->fire_on=1;
  114.     return move_player(op, params?atoi(params):0);
  115. }
  116.  
  117. int command_fire_stop(object *op, char *params)
  118. {
  119.     op->contr->fire_on=0;
  120.     return 1;
  121. }
  122.  
  123. int bad_command(object *op, char *params)
  124. {
  125.     new_draw_info(NDI_UNIQUE, 0,op,"bind and unbind are no longer handled on the server");
  126.     return 1;
  127. }
  128.